﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;

namespace WDTAsg2.DbBizObject
{
    public class CategoryInfo
    {


        /// <summary>
        /// Gets all the parent categories
        /// </summary>
        /// <returns></returns>
        public static SqlDataReader GetParentCategories()
        {
            string conString = ConfigurationManager.ConnectionStrings["HardwaresRUsCS"].ConnectionString;

            // Call stored proc
            SqlConnection con = new SqlConnection(conString);
            SqlCommand cmd = new SqlCommand("getParentCategories", con);
            cmd.CommandType = CommandType.StoredProcedure;

            con.Open();
            SqlDataReader dtr = cmd.ExecuteReader();

            //con.Close();

            return dtr;
        }

        /// <summary>
        /// Gets all the child categories (not parent)
        /// </summary>
        /// <returns></returns>
        public static SqlDataReader GetAllChildCategories()
        {
            string conString = ConfigurationManager.ConnectionStrings["HardwaresRUsCS"].ConnectionString;

            // Stored proc
            SqlConnection con = new SqlConnection(conString);
            SqlCommand cmd = new SqlCommand("getAllChildCategories", con);
            cmd.CommandType = CommandType.StoredProcedure;

            con.Open();
            SqlDataReader dtr = cmd.ExecuteReader();

            //con.Close();

            return dtr;
        }




        /// <summary>
        /// Gets all child categories belowing to a parent
        /// </summary>
        /// <param name="parentId"></param>
        /// <returns></returns>
        public static SqlDataReader GetChildCategories(int parentId)
        {
            string conString = ConfigurationManager.ConnectionStrings["HardwaresRUsCS"].ConnectionString;

            // Stored proc
            SqlConnection con = new SqlConnection(conString);
            SqlCommand cmd = new SqlCommand("getChildCategories", con);
            cmd.CommandType = CommandType.StoredProcedure;

            cmd.Parameters.AddWithValue("@ParentId", parentId);

            con.Open();
            SqlDataReader dtr = cmd.ExecuteReader();

            //con.Close();

            return dtr;
        }



    }
}